package com.cim.web;

import com.cim.pojo.Video;
import com.cim.service.VideoService;
import com.cim.utils.ResponseUtil;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;



//RTMP认证测试
//RTMP认证请求为POST请求,注意获取数据方式
@RestController
@RequestMapping("/rtmp")
public class RtmpAuth {

    @Autowired
    VideoService videoService;
    //RTMP推流认证
    @PostMapping("/push")
    public Object pushAuth(@RequestParam String name,@RequestParam String key, HttpServletResponse resp){
        //查找视频ID是否存在
        Video video=videoService.getVideo(name);

        int code=403;
        if(video!=null){
            if(video.getPushKey().equals(name+"?key="+key)){    //验证秘钥
                if(video.getPlayBack()!=2){  //状态不为直播结束
                    video.setPlayBack(1);   //设置为直播中
                    videoService.updateVideo(video);
                    code=200;
                }
            }
        }
        resp.setStatus(code);
        return ResponseUtil.fail(code,"");
    }
}
